﻿#ifndef DETECTIONDLG_H
#define DETECTIONDLG_H

#include <QDialog>
#include <QFileDialog>
#include <QImage>
#include "Common/common.h"
#include "Alg/measure_size.h"
#include "Alg/measure_cricle.h"
#include "Alg/Defect.h"
#include "Alg/calibration.h"
#include "Alg/measure_area.h"
#include "roidlg.h"
#include <QTimer>
#include <QTime>

namespace Ui {
class DetectionDlg;
}

class DetectionDlg : public QDialog
{
    Q_OBJECT

public:
    explicit DetectionDlg(QWidget *parent = 0);
    ~DetectionDlg();
    void CameraList(int nIndex);
    void HalconOpenwindows();

    void CarouselImage(QString OpenFile);
    void DetectionSize(HObject Hobj);
    void DetectionCricle(HObject Hobj);

    void DetectionDefect(HObject Hobj,int nIndex);

    void ShowImage(HObject img);

    void ShowImage(HObject img, HTuple hv_WindowHandle,int index);


    bool eventFilter(QObject *obj, QEvent *event);



    bool deleteDir(const QString &path);


    void SetAllToolTip();

    void RedAlgPlaceIni();
signals:
    void changeDlg(int Index);
    void sigDltoDetection(DetectionDlgInfo detectionInfo);
private slots:
    void on_switchBt_1_clicked();

    void on_switchBt_3_clicked();

    void on_switchBt_2_clicked();

    void on_switchBt_4_clicked();

    void on_OpenFileBt_clicked();

    void on_camear_1_clicked();

    void on_camear_2_clicked();

    void on_camear_3_clicked();

    void on_camear_4_clicked();

    void on_writeBt_clicked();

    void on_cameraBt_1_clicked();

    void on_cameraBt_2_clicked();

    void on_clearBt_clicked();

    void on_upBt_clicked();

    void on_downBt_clicked();

    void on_staticBt_clicked();

    void on_areaBt_clicked();

    void on_SetRoiBt_clicked();


    void systimer();

public:
    Ui::DetectionDlg *ui;
    HalconCpp::HObject Hobj;

    HalconCpp::HObject ho_GrayImage;  //要检测灰度值的图像



    HalconCpp::HTuple hv_WindowHandle;
    bool m_bOpen = false;


    Measure_Cricle m_AlgCricle;
    Measure_Size m_AlgSize;
    Defect m_AlgDefect;
    DetectionDlgInfo m_detectionInfo;
    int m_nCamera_1 = 0;
    int m_nCamera_2 = 0;
    int m_nCamera_3 = 0;
    int m_nCamera_4 = 0;

    int m_nTexHeight = 0;

    int m_nTexX = 0;
    int m_nTexY = 0;

    HTuple In_Round;
    HTuple Out_Round;
    HTuple In_Len;
    HTuple Out_Len;

    HTuple Len;

    int m_nNGorOK = 0;

    // 相机标定
    calibration m_cal;


    // 图片切换
    QString file_path; // 当前文件路径
    QStringList file_list; // 文件内图片
    QString file_name;
    int m_nImgIndex = 0;


    // 面积计算
    measure_area m_AlgArea;

    // 缩放放大比例
    int part = 0;

    // Roi区域
    RoiDlg *m_dRoi;
    QString msg;



    QTimer *myTimer;
    int m_nTest = 0;

};

#endif // DETECTIONDLG_H
